//
//  HDMonthModle.m
//  MirkoLibTest
//
//  Created by Mirko on 2017/1/20.
//  Copyright © 2017年 Mirko. All rights reserved.
//

#import "HDMonthModle.h"

@interface HDMonthModle ()

//传进来的参数
@property (nonatomic, strong) NSString *dataStr;

@end

@implementation HDMonthModle

//参数解析成model
+(instancetype) modleWithFullDate:(NSString *) dataStr
{
    HDMonthModle *modle = [[HDMonthModle alloc] init];
    modle.dataStr = dataStr;
    return modle;
}

+(instancetype) modleWithTimeInterval:(NSNumber *) dataStr
{
    NSTimeInterval interval = [dataStr doubleValue];
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:interval];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSString *dateStr = [formatter stringFromDate:date];
    return [HDMonthModle modleWithFullDate:dateStr];
}


+(instancetype) modleWithYear:(NSString *) year month:(NSString *) month;
{
    NSString *string = [NSString stringWithFormat:@"%@-%@", year, month];
    return [HDMonthModle modleWithFullDate:string];
}

-(instancetype) init
{
    self = [super init];
    if (self) {
        self.eMonth = @"13";
    }
    return self;
}

-(void) setDataStr:(NSString *)dataStr
{
    [self parseDataStr:dataStr];
    _dataStr = dataStr;
}

-(void) parseDataStr:(NSString *) dataStr
{
    NSArray *subItem = [dataStr componentsSeparatedByString:@"-"];
    self.year = subItem[0];
    self.nYear = [self.year integerValue];
    self.month = subItem[1];
    self.nMonth = [self.month integerValue];
    
}

-(NSInteger) nEMonth
{
    return [self.eMonth integerValue];
}

-(NSString *) dataPara
{
    NSString *result = [NSString stringWithFormat:@"%@-%@", self.year, self.month];
    return result;
}

-(BOOL) isInvalidTime
{
    if (self.nMonth == 13) {
        return YES;
    }
    return NO; 
}

-(BOOL) sameAsTime:(HDMonthModle *) time
{
    if (time.nMonth == self.nMonth && time.nYear == self.nYear) {
        return YES;
    }
    return NO;
}

@end
